<template>
  <!-- 中间热歌推荐列表 -->
  <div class="main-content">
    <div class="title">{{ title }}</div>
    <!-- 加载状态 -->
    <p v-if="isLoading" class="loading-message">正在加载歌曲列表...</p>
    <!-- 错误信息 -->
    <p v-if="errorMessage" class="error-message">{{ errorMessage }}</p>
    <!-- 歌曲列表 -->
    <div v-if="!isLoading &&!errorMessage" class="song-list">
      <div v-for="song in songs" :key="song.id" class="song-item">
        <span>{{ song.id }}</span>
        <span>{{ song.title }}</span>
        <span>{{ song.artist }}</span>
        <button v-if="add" @click="addToNext(song)" class="add-button">添加</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

// 接收父组件传递的 props
const props = defineProps({
  songs: {
    type: Array,
    default: () => []
  },
  isLoading: {
    type: Boolean,
    default: false
  },
  errorMessage: {
    type: String,
    default: ''
  },
  title: {
    type: String,
    default: '热歌推荐'
  },
  add: {
    type: Boolean,
    default: true
  }
});

// 接收父组件传递的方法
const emit = defineEmits(['addToNext']);

const addToNext = (song) => {
  emit('addToNext', song);
};
</script>

<style scoped>
/* 这里可以保留原有的样式，也可以根据需要进行调整 */
.loading-message {
  text-align: center;
  color: #777;
  font-size: 1.2rem;
}

.error-message {
  text-align: center;
  color: #e74c3c;
  font-size: 1.2rem;
}

.song-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: calc(93% - 2rem);
  overflow-y: auto;
}

/* WebKit 浏览器（Chrome、Safari 等）的滚动条样式 */
.song-list::-webkit-scrollbar {
  width: 4px;
}

.song-list::-webkit-scrollbar-track {
  background: #f4f4f9;
  border-radius: 4px;
}

.song-list::-webkit-scrollbar-thumb {
  background-color: #3498db;
  border-radius: 4px;
  border: 1px solid #f4f4f9;
}

.song-list::-webkit-scrollbar-thumb:hover {
  background-color: #2980b9;
}

.song-item {
  /* 修改背景为渐变色 */
  /* background: linear-gradient(to right, #e0f7fa, #b2ebf2);  */
  padding: 0.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  display: flex;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.song-item span {
  flex: 1;
  text-align: left;
  padding-left: 1rem;
}
</style>